package com.xintong.visualinspection.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.Webcam;
import com.xintong.visualinspection.service.WebcamService;

/**
 * 文件名：TestController
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
/**
 * @author wenhongquan
 *
 */
@RestController
@RequestMapping("/webcam")
public class WebcamController extends BaseController {

	@Autowired
	private WebcamService webcamService;

	@RequestMapping(value = "/getAllVideo/{page}/{size}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public String getAllVideo(@PathVariable Integer page, @PathVariable Integer size) {
		try {
			PageHelper.startPage(page, size);
			List<Webcam> webcams = webcamService.getAll();

			return returnResult(0, "获取成功", new PageInfo(webcams));
		} catch (Exception e) {
			throw new BusinessException(20001);
		}
	}

	@RequestMapping(value = "/getVideoByDeptAndLane/{page}/{size}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String getVideoByDeptAndLane(@PathVariable Integer page, @PathVariable Integer size,
			@RequestBody Webcam webcam) {
		try {
			PageHelper.startPage(page, size);
			List<Webcam> webcams = webcamService.getWebcams(webcam);

			return returnResult(0, "获取成功", new PageInfo(webcams));
		} catch (Exception e) {
			throw new BusinessException(20001);
		}
	}

	@RequestMapping(value = "/getVideoById/{webcamid}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public String getVideoById(@PathVariable Integer webcamid) {
		try {
			Webcam u = webcamService.getOne(webcamid);
			return returnResult(0, "获取成功", u);
		} catch (Exception e) {
			throw new BusinessException(20001);
		}
	}

}
